package com.xjgzinfo.usdp.web.rest;

import com.xjgzinfo.usdp.AvueServer4jApp;
import com.xjgzinfo.usdp.config.TestSecurityConfiguration;
import com.xjgzinfo.usdp.domain.TemplateMarket;
import com.xjgzinfo.usdp.domain.TemplateScoreRecord;
import com.xjgzinfo.usdp.repository.TemplateMarketRepository;
import com.xjgzinfo.usdp.service.TemplateMarketService;
import com.xjgzinfo.usdp.service.dto.TemplateMarketDTO;
import com.xjgzinfo.usdp.service.mapper.TemplateMarketMapper;
import com.xjgzinfo.usdp.service.dto.TemplateMarketCriteria;
import com.xjgzinfo.usdp.service.TemplateMarketQueryService;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;
import javax.persistence.EntityManager;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

/**
 * Integration tests for the {@link TemplateMarketResource} REST controller.
 */
@SpringBootTest(classes = { AvueServer4jApp.class, TestSecurityConfiguration.class })
@AutoConfigureMockMvc
@WithMockUser
public class TemplateMarketResourceIT {

    private static final Long DEFAULT_TEMPLATE_ID = 1L;
    private static final Long UPDATED_TEMPLATE_ID = 2L;
    private static final Long SMALLER_TEMPLATE_ID = 1L - 1L;

    private static final Long DEFAULT_APP_CLASS_ID = 1L;
    private static final Long UPDATED_APP_CLASS_ID = 2L;
    private static final Long SMALLER_APP_CLASS_ID = 1L - 1L;

    private static final String DEFAULT_PAGE_SCHEMA_IDS = "AAAAAAAAAA";
    private static final String UPDATED_PAGE_SCHEMA_IDS = "BBBBBBBBBB";

    private static final String DEFAULT_ASSETS_TYPE = "AAAAAAAAAA";
    private static final String UPDATED_ASSETS_TYPE = "BBBBBBBBBB";

    private static final String DEFAULT_CREATE_USER = "AAAAAAAAAA";
    private static final String UPDATED_CREATE_USER = "BBBBBBBBBB";

    private static final Instant DEFAULT_CREATE_TIME = Instant.ofEpochMilli(0L);
    private static final Instant UPDATED_CREATE_TIME = Instant.now().truncatedTo(ChronoUnit.MILLIS);

    private static final String DEFAULT_APP_CLASS_NAME = "AAAAAAAAAA";
    private static final String UPDATED_APP_CLASS_NAME = "BBBBBBBBBB";

    private static final String DEFAULT_DESCRIPTION = "AAAAAAAAAA";
    private static final String UPDATED_DESCRIPTION = "BBBBBBBBBB";

    private static final Long DEFAULT_TEMPLATE_TYPE_ID = 1L;
    private static final Long UPDATED_TEMPLATE_TYPE_ID = 2L;
    private static final Long SMALLER_TEMPLATE_TYPE_ID = 1L - 1L;

    @Autowired
    private TemplateMarketRepository templateMarketRepository;

    @Autowired
    private TemplateMarketMapper templateMarketMapper;

    @Autowired
    private TemplateMarketService templateMarketService;

    @Autowired
    private TemplateMarketQueryService templateMarketQueryService;

    @Autowired
    private EntityManager em;

    @Autowired
    private MockMvc restTemplateMarketMockMvc;

    private TemplateMarket templateMarket;

    /**
     * Create an entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static TemplateMarket createEntity(EntityManager em) {
        TemplateMarket templateMarket = new TemplateMarket()
            .templateId(DEFAULT_TEMPLATE_ID)
            .appClassId(DEFAULT_APP_CLASS_ID)
            .pageSchemaIds(DEFAULT_PAGE_SCHEMA_IDS)
            .assetsType(DEFAULT_ASSETS_TYPE)
            .createUser(DEFAULT_CREATE_USER)
            .createTime(DEFAULT_CREATE_TIME)
            .appClassName(DEFAULT_APP_CLASS_NAME)
            .description(DEFAULT_DESCRIPTION)
            .templateTypeId(DEFAULT_TEMPLATE_TYPE_ID);
        return templateMarket;
    }
    /**
     * Create an updated entity for this test.
     *
     * This is a static method, as tests for other entities might also need it,
     * if they test an entity which requires the current entity.
     */
    public static TemplateMarket createUpdatedEntity(EntityManager em) {
        TemplateMarket templateMarket = new TemplateMarket()
            .templateId(UPDATED_TEMPLATE_ID)
            .appClassId(UPDATED_APP_CLASS_ID)
            .pageSchemaIds(UPDATED_PAGE_SCHEMA_IDS)
            .assetsType(UPDATED_ASSETS_TYPE)
            .createUser(UPDATED_CREATE_USER)
            .createTime(UPDATED_CREATE_TIME)
            .appClassName(UPDATED_APP_CLASS_NAME)
            .description(UPDATED_DESCRIPTION)
            .templateTypeId(UPDATED_TEMPLATE_TYPE_ID);
        return templateMarket;
    }

    @BeforeEach
    public void initTest() {
        templateMarket = createEntity(em);
    }

    @Test
    @Transactional
    public void createTemplateMarket() throws Exception {
        int databaseSizeBeforeCreate = templateMarketRepository.findAll().size();
        // Create the TemplateMarket
        TemplateMarketDTO templateMarketDTO = templateMarketMapper.toDto(templateMarket);
        restTemplateMarketMockMvc.perform(post("/api/template-markets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateMarketDTO)))
            .andExpect(status().isCreated());

        // Validate the TemplateMarket in the database
        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeCreate + 1);
        TemplateMarket testTemplateMarket = templateMarketList.get(templateMarketList.size() - 1);
        assertThat(testTemplateMarket.getTemplateId()).isEqualTo(DEFAULT_TEMPLATE_ID);
        assertThat(testTemplateMarket.getAppClassId()).isEqualTo(DEFAULT_APP_CLASS_ID);
        assertThat(testTemplateMarket.getPageSchemaIds()).isEqualTo(DEFAULT_PAGE_SCHEMA_IDS);
        assertThat(testTemplateMarket.getAssetsType()).isEqualTo(DEFAULT_ASSETS_TYPE);
        assertThat(testTemplateMarket.getCreateUser()).isEqualTo(DEFAULT_CREATE_USER);
        assertThat(testTemplateMarket.getCreateTime()).isEqualTo(DEFAULT_CREATE_TIME);
        assertThat(testTemplateMarket.getAppClassName()).isEqualTo(DEFAULT_APP_CLASS_NAME);
        assertThat(testTemplateMarket.getDescription()).isEqualTo(DEFAULT_DESCRIPTION);
        assertThat(testTemplateMarket.getTemplateTypeId()).isEqualTo(DEFAULT_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void createTemplateMarketWithExistingId() throws Exception {
        int databaseSizeBeforeCreate = templateMarketRepository.findAll().size();

        // Create the TemplateMarket with an existing ID
        templateMarket.setId(1L);
        TemplateMarketDTO templateMarketDTO = templateMarketMapper.toDto(templateMarket);

        // An entity with an existing ID cannot be created, so this API call must fail
        restTemplateMarketMockMvc.perform(post("/api/template-markets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateMarketDTO)))
            .andExpect(status().isBadRequest());

        // Validate the TemplateMarket in the database
        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeCreate);
    }


    @Test
    @Transactional
    public void checkTemplateIdIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateMarketRepository.findAll().size();
        // set the field null
        templateMarket.setTemplateId(null);

        // Create the TemplateMarket, which fails.
        TemplateMarketDTO templateMarketDTO = templateMarketMapper.toDto(templateMarket);


        restTemplateMarketMockMvc.perform(post("/api/template-markets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateMarketDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkAppClassIdIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateMarketRepository.findAll().size();
        // set the field null
        templateMarket.setAppClassId(null);

        // Create the TemplateMarket, which fails.
        TemplateMarketDTO templateMarketDTO = templateMarketMapper.toDto(templateMarket);


        restTemplateMarketMockMvc.perform(post("/api/template-markets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateMarketDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void checkAssetsTypeIsRequired() throws Exception {
        int databaseSizeBeforeTest = templateMarketRepository.findAll().size();
        // set the field null
        templateMarket.setAssetsType(null);

        // Create the TemplateMarket, which fails.
        TemplateMarketDTO templateMarketDTO = templateMarketMapper.toDto(templateMarket);


        restTemplateMarketMockMvc.perform(post("/api/template-markets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateMarketDTO)))
            .andExpect(status().isBadRequest());

        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeTest);
    }

    @Test
    @Transactional
    public void getAllTemplateMarkets() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList
        restTemplateMarketMockMvc.perform(get("/api/template-markets?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(templateMarket.getId().intValue())))
            .andExpect(jsonPath("$.[*].templateId").value(hasItem(DEFAULT_TEMPLATE_ID.intValue())))
            .andExpect(jsonPath("$.[*].appClassId").value(hasItem(DEFAULT_APP_CLASS_ID.intValue())))
            .andExpect(jsonPath("$.[*].pageSchemaIds").value(hasItem(DEFAULT_PAGE_SCHEMA_IDS.toString())))
            .andExpect(jsonPath("$.[*].assetsType").value(hasItem(DEFAULT_ASSETS_TYPE)))
            .andExpect(jsonPath("$.[*].createUser").value(hasItem(DEFAULT_CREATE_USER)))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].appClassName").value(hasItem(DEFAULT_APP_CLASS_NAME)))
            .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString())))
            .andExpect(jsonPath("$.[*].templateTypeId").value(hasItem(DEFAULT_TEMPLATE_TYPE_ID.intValue())));
    }
    
    @Test
    @Transactional
    public void getTemplateMarket() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get the templateMarket
        restTemplateMarketMockMvc.perform(get("/api/template-markets/{id}", templateMarket.getId()))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.id").value(templateMarket.getId().intValue()))
            .andExpect(jsonPath("$.templateId").value(DEFAULT_TEMPLATE_ID.intValue()))
            .andExpect(jsonPath("$.appClassId").value(DEFAULT_APP_CLASS_ID.intValue()))
            .andExpect(jsonPath("$.pageSchemaIds").value(DEFAULT_PAGE_SCHEMA_IDS.toString()))
            .andExpect(jsonPath("$.assetsType").value(DEFAULT_ASSETS_TYPE))
            .andExpect(jsonPath("$.createUser").value(DEFAULT_CREATE_USER))
            .andExpect(jsonPath("$.createTime").value(DEFAULT_CREATE_TIME.toString()))
            .andExpect(jsonPath("$.appClassName").value(DEFAULT_APP_CLASS_NAME))
            .andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString()))
            .andExpect(jsonPath("$.templateTypeId").value(DEFAULT_TEMPLATE_TYPE_ID.intValue()));
    }


    @Test
    @Transactional
    public void getTemplateMarketsByIdFiltering() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        Long id = templateMarket.getId();

        defaultTemplateMarketShouldBeFound("id.equals=" + id);
        defaultTemplateMarketShouldNotBeFound("id.notEquals=" + id);

        defaultTemplateMarketShouldBeFound("id.greaterThanOrEqual=" + id);
        defaultTemplateMarketShouldNotBeFound("id.greaterThan=" + id);

        defaultTemplateMarketShouldBeFound("id.lessThanOrEqual=" + id);
        defaultTemplateMarketShouldNotBeFound("id.lessThan=" + id);
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId equals to DEFAULT_TEMPLATE_ID
        defaultTemplateMarketShouldBeFound("templateId.equals=" + DEFAULT_TEMPLATE_ID);

        // Get all the templateMarketList where templateId equals to UPDATED_TEMPLATE_ID
        defaultTemplateMarketShouldNotBeFound("templateId.equals=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId not equals to DEFAULT_TEMPLATE_ID
        defaultTemplateMarketShouldNotBeFound("templateId.notEquals=" + DEFAULT_TEMPLATE_ID);

        // Get all the templateMarketList where templateId not equals to UPDATED_TEMPLATE_ID
        defaultTemplateMarketShouldBeFound("templateId.notEquals=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsInShouldWork() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId in DEFAULT_TEMPLATE_ID or UPDATED_TEMPLATE_ID
        defaultTemplateMarketShouldBeFound("templateId.in=" + DEFAULT_TEMPLATE_ID + "," + UPDATED_TEMPLATE_ID);

        // Get all the templateMarketList where templateId equals to UPDATED_TEMPLATE_ID
        defaultTemplateMarketShouldNotBeFound("templateId.in=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId is not null
        defaultTemplateMarketShouldBeFound("templateId.specified=true");

        // Get all the templateMarketList where templateId is null
        defaultTemplateMarketShouldNotBeFound("templateId.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId is greater than or equal to DEFAULT_TEMPLATE_ID
        defaultTemplateMarketShouldBeFound("templateId.greaterThanOrEqual=" + DEFAULT_TEMPLATE_ID);

        // Get all the templateMarketList where templateId is greater than or equal to UPDATED_TEMPLATE_ID
        defaultTemplateMarketShouldNotBeFound("templateId.greaterThanOrEqual=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId is less than or equal to DEFAULT_TEMPLATE_ID
        defaultTemplateMarketShouldBeFound("templateId.lessThanOrEqual=" + DEFAULT_TEMPLATE_ID);

        // Get all the templateMarketList where templateId is less than or equal to SMALLER_TEMPLATE_ID
        defaultTemplateMarketShouldNotBeFound("templateId.lessThanOrEqual=" + SMALLER_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsLessThanSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId is less than DEFAULT_TEMPLATE_ID
        defaultTemplateMarketShouldNotBeFound("templateId.lessThan=" + DEFAULT_TEMPLATE_ID);

        // Get all the templateMarketList where templateId is less than UPDATED_TEMPLATE_ID
        defaultTemplateMarketShouldBeFound("templateId.lessThan=" + UPDATED_TEMPLATE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateId is greater than DEFAULT_TEMPLATE_ID
        defaultTemplateMarketShouldNotBeFound("templateId.greaterThan=" + DEFAULT_TEMPLATE_ID);

        // Get all the templateMarketList where templateId is greater than SMALLER_TEMPLATE_ID
        defaultTemplateMarketShouldBeFound("templateId.greaterThan=" + SMALLER_TEMPLATE_ID);
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId equals to DEFAULT_APP_CLASS_ID
        defaultTemplateMarketShouldBeFound("appClassId.equals=" + DEFAULT_APP_CLASS_ID);

        // Get all the templateMarketList where appClassId equals to UPDATED_APP_CLASS_ID
        defaultTemplateMarketShouldNotBeFound("appClassId.equals=" + UPDATED_APP_CLASS_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId not equals to DEFAULT_APP_CLASS_ID
        defaultTemplateMarketShouldNotBeFound("appClassId.notEquals=" + DEFAULT_APP_CLASS_ID);

        // Get all the templateMarketList where appClassId not equals to UPDATED_APP_CLASS_ID
        defaultTemplateMarketShouldBeFound("appClassId.notEquals=" + UPDATED_APP_CLASS_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsInShouldWork() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId in DEFAULT_APP_CLASS_ID or UPDATED_APP_CLASS_ID
        defaultTemplateMarketShouldBeFound("appClassId.in=" + DEFAULT_APP_CLASS_ID + "," + UPDATED_APP_CLASS_ID);

        // Get all the templateMarketList where appClassId equals to UPDATED_APP_CLASS_ID
        defaultTemplateMarketShouldNotBeFound("appClassId.in=" + UPDATED_APP_CLASS_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId is not null
        defaultTemplateMarketShouldBeFound("appClassId.specified=true");

        // Get all the templateMarketList where appClassId is null
        defaultTemplateMarketShouldNotBeFound("appClassId.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId is greater than or equal to DEFAULT_APP_CLASS_ID
        defaultTemplateMarketShouldBeFound("appClassId.greaterThanOrEqual=" + DEFAULT_APP_CLASS_ID);

        // Get all the templateMarketList where appClassId is greater than or equal to UPDATED_APP_CLASS_ID
        defaultTemplateMarketShouldNotBeFound("appClassId.greaterThanOrEqual=" + UPDATED_APP_CLASS_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId is less than or equal to DEFAULT_APP_CLASS_ID
        defaultTemplateMarketShouldBeFound("appClassId.lessThanOrEqual=" + DEFAULT_APP_CLASS_ID);

        // Get all the templateMarketList where appClassId is less than or equal to SMALLER_APP_CLASS_ID
        defaultTemplateMarketShouldNotBeFound("appClassId.lessThanOrEqual=" + SMALLER_APP_CLASS_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsLessThanSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId is less than DEFAULT_APP_CLASS_ID
        defaultTemplateMarketShouldNotBeFound("appClassId.lessThan=" + DEFAULT_APP_CLASS_ID);

        // Get all the templateMarketList where appClassId is less than UPDATED_APP_CLASS_ID
        defaultTemplateMarketShouldBeFound("appClassId.lessThan=" + UPDATED_APP_CLASS_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassId is greater than DEFAULT_APP_CLASS_ID
        defaultTemplateMarketShouldNotBeFound("appClassId.greaterThan=" + DEFAULT_APP_CLASS_ID);

        // Get all the templateMarketList where appClassId is greater than SMALLER_APP_CLASS_ID
        defaultTemplateMarketShouldBeFound("appClassId.greaterThan=" + SMALLER_APP_CLASS_ID);
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByAssetsTypeIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where assetsType equals to DEFAULT_ASSETS_TYPE
        defaultTemplateMarketShouldBeFound("assetsType.equals=" + DEFAULT_ASSETS_TYPE);

        // Get all the templateMarketList where assetsType equals to UPDATED_ASSETS_TYPE
        defaultTemplateMarketShouldNotBeFound("assetsType.equals=" + UPDATED_ASSETS_TYPE);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAssetsTypeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where assetsType not equals to DEFAULT_ASSETS_TYPE
        defaultTemplateMarketShouldNotBeFound("assetsType.notEquals=" + DEFAULT_ASSETS_TYPE);

        // Get all the templateMarketList where assetsType not equals to UPDATED_ASSETS_TYPE
        defaultTemplateMarketShouldBeFound("assetsType.notEquals=" + UPDATED_ASSETS_TYPE);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAssetsTypeIsInShouldWork() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where assetsType in DEFAULT_ASSETS_TYPE or UPDATED_ASSETS_TYPE
        defaultTemplateMarketShouldBeFound("assetsType.in=" + DEFAULT_ASSETS_TYPE + "," + UPDATED_ASSETS_TYPE);

        // Get all the templateMarketList where assetsType equals to UPDATED_ASSETS_TYPE
        defaultTemplateMarketShouldNotBeFound("assetsType.in=" + UPDATED_ASSETS_TYPE);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAssetsTypeIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where assetsType is not null
        defaultTemplateMarketShouldBeFound("assetsType.specified=true");

        // Get all the templateMarketList where assetsType is null
        defaultTemplateMarketShouldNotBeFound("assetsType.specified=false");
    }
                @Test
    @Transactional
    public void getAllTemplateMarketsByAssetsTypeContainsSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where assetsType contains DEFAULT_ASSETS_TYPE
        defaultTemplateMarketShouldBeFound("assetsType.contains=" + DEFAULT_ASSETS_TYPE);

        // Get all the templateMarketList where assetsType contains UPDATED_ASSETS_TYPE
        defaultTemplateMarketShouldNotBeFound("assetsType.contains=" + UPDATED_ASSETS_TYPE);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAssetsTypeNotContainsSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where assetsType does not contain DEFAULT_ASSETS_TYPE
        defaultTemplateMarketShouldNotBeFound("assetsType.doesNotContain=" + DEFAULT_ASSETS_TYPE);

        // Get all the templateMarketList where assetsType does not contain UPDATED_ASSETS_TYPE
        defaultTemplateMarketShouldBeFound("assetsType.doesNotContain=" + UPDATED_ASSETS_TYPE);
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateUserIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createUser equals to DEFAULT_CREATE_USER
        defaultTemplateMarketShouldBeFound("createUser.equals=" + DEFAULT_CREATE_USER);

        // Get all the templateMarketList where createUser equals to UPDATED_CREATE_USER
        defaultTemplateMarketShouldNotBeFound("createUser.equals=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateUserIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createUser not equals to DEFAULT_CREATE_USER
        defaultTemplateMarketShouldNotBeFound("createUser.notEquals=" + DEFAULT_CREATE_USER);

        // Get all the templateMarketList where createUser not equals to UPDATED_CREATE_USER
        defaultTemplateMarketShouldBeFound("createUser.notEquals=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateUserIsInShouldWork() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createUser in DEFAULT_CREATE_USER or UPDATED_CREATE_USER
        defaultTemplateMarketShouldBeFound("createUser.in=" + DEFAULT_CREATE_USER + "," + UPDATED_CREATE_USER);

        // Get all the templateMarketList where createUser equals to UPDATED_CREATE_USER
        defaultTemplateMarketShouldNotBeFound("createUser.in=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateUserIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createUser is not null
        defaultTemplateMarketShouldBeFound("createUser.specified=true");

        // Get all the templateMarketList where createUser is null
        defaultTemplateMarketShouldNotBeFound("createUser.specified=false");
    }
                @Test
    @Transactional
    public void getAllTemplateMarketsByCreateUserContainsSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createUser contains DEFAULT_CREATE_USER
        defaultTemplateMarketShouldBeFound("createUser.contains=" + DEFAULT_CREATE_USER);

        // Get all the templateMarketList where createUser contains UPDATED_CREATE_USER
        defaultTemplateMarketShouldNotBeFound("createUser.contains=" + UPDATED_CREATE_USER);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateUserNotContainsSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createUser does not contain DEFAULT_CREATE_USER
        defaultTemplateMarketShouldNotBeFound("createUser.doesNotContain=" + DEFAULT_CREATE_USER);

        // Get all the templateMarketList where createUser does not contain UPDATED_CREATE_USER
        defaultTemplateMarketShouldBeFound("createUser.doesNotContain=" + UPDATED_CREATE_USER);
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateTimeIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createTime equals to DEFAULT_CREATE_TIME
        defaultTemplateMarketShouldBeFound("createTime.equals=" + DEFAULT_CREATE_TIME);

        // Get all the templateMarketList where createTime equals to UPDATED_CREATE_TIME
        defaultTemplateMarketShouldNotBeFound("createTime.equals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateTimeIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createTime not equals to DEFAULT_CREATE_TIME
        defaultTemplateMarketShouldNotBeFound("createTime.notEquals=" + DEFAULT_CREATE_TIME);

        // Get all the templateMarketList where createTime not equals to UPDATED_CREATE_TIME
        defaultTemplateMarketShouldBeFound("createTime.notEquals=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateTimeIsInShouldWork() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createTime in DEFAULT_CREATE_TIME or UPDATED_CREATE_TIME
        defaultTemplateMarketShouldBeFound("createTime.in=" + DEFAULT_CREATE_TIME + "," + UPDATED_CREATE_TIME);

        // Get all the templateMarketList where createTime equals to UPDATED_CREATE_TIME
        defaultTemplateMarketShouldNotBeFound("createTime.in=" + UPDATED_CREATE_TIME);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByCreateTimeIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where createTime is not null
        defaultTemplateMarketShouldBeFound("createTime.specified=true");

        // Get all the templateMarketList where createTime is null
        defaultTemplateMarketShouldNotBeFound("createTime.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassNameIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassName equals to DEFAULT_APP_CLASS_NAME
        defaultTemplateMarketShouldBeFound("appClassName.equals=" + DEFAULT_APP_CLASS_NAME);

        // Get all the templateMarketList where appClassName equals to UPDATED_APP_CLASS_NAME
        defaultTemplateMarketShouldNotBeFound("appClassName.equals=" + UPDATED_APP_CLASS_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassNameIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassName not equals to DEFAULT_APP_CLASS_NAME
        defaultTemplateMarketShouldNotBeFound("appClassName.notEquals=" + DEFAULT_APP_CLASS_NAME);

        // Get all the templateMarketList where appClassName not equals to UPDATED_APP_CLASS_NAME
        defaultTemplateMarketShouldBeFound("appClassName.notEquals=" + UPDATED_APP_CLASS_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassNameIsInShouldWork() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassName in DEFAULT_APP_CLASS_NAME or UPDATED_APP_CLASS_NAME
        defaultTemplateMarketShouldBeFound("appClassName.in=" + DEFAULT_APP_CLASS_NAME + "," + UPDATED_APP_CLASS_NAME);

        // Get all the templateMarketList where appClassName equals to UPDATED_APP_CLASS_NAME
        defaultTemplateMarketShouldNotBeFound("appClassName.in=" + UPDATED_APP_CLASS_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassNameIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassName is not null
        defaultTemplateMarketShouldBeFound("appClassName.specified=true");

        // Get all the templateMarketList where appClassName is null
        defaultTemplateMarketShouldNotBeFound("appClassName.specified=false");
    }
                @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassNameContainsSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassName contains DEFAULT_APP_CLASS_NAME
        defaultTemplateMarketShouldBeFound("appClassName.contains=" + DEFAULT_APP_CLASS_NAME);

        // Get all the templateMarketList where appClassName contains UPDATED_APP_CLASS_NAME
        defaultTemplateMarketShouldNotBeFound("appClassName.contains=" + UPDATED_APP_CLASS_NAME);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByAppClassNameNotContainsSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where appClassName does not contain DEFAULT_APP_CLASS_NAME
        defaultTemplateMarketShouldNotBeFound("appClassName.doesNotContain=" + DEFAULT_APP_CLASS_NAME);

        // Get all the templateMarketList where appClassName does not contain UPDATED_APP_CLASS_NAME
        defaultTemplateMarketShouldBeFound("appClassName.doesNotContain=" + UPDATED_APP_CLASS_NAME);
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId equals to DEFAULT_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldBeFound("templateTypeId.equals=" + DEFAULT_TEMPLATE_TYPE_ID);

        // Get all the templateMarketList where templateTypeId equals to UPDATED_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldNotBeFound("templateTypeId.equals=" + UPDATED_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsNotEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId not equals to DEFAULT_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldNotBeFound("templateTypeId.notEquals=" + DEFAULT_TEMPLATE_TYPE_ID);

        // Get all the templateMarketList where templateTypeId not equals to UPDATED_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldBeFound("templateTypeId.notEquals=" + UPDATED_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsInShouldWork() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId in DEFAULT_TEMPLATE_TYPE_ID or UPDATED_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldBeFound("templateTypeId.in=" + DEFAULT_TEMPLATE_TYPE_ID + "," + UPDATED_TEMPLATE_TYPE_ID);

        // Get all the templateMarketList where templateTypeId equals to UPDATED_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldNotBeFound("templateTypeId.in=" + UPDATED_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsNullOrNotNull() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId is not null
        defaultTemplateMarketShouldBeFound("templateTypeId.specified=true");

        // Get all the templateMarketList where templateTypeId is null
        defaultTemplateMarketShouldNotBeFound("templateTypeId.specified=false");
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsGreaterThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId is greater than or equal to DEFAULT_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldBeFound("templateTypeId.greaterThanOrEqual=" + DEFAULT_TEMPLATE_TYPE_ID);

        // Get all the templateMarketList where templateTypeId is greater than or equal to UPDATED_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldNotBeFound("templateTypeId.greaterThanOrEqual=" + UPDATED_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsLessThanOrEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId is less than or equal to DEFAULT_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldBeFound("templateTypeId.lessThanOrEqual=" + DEFAULT_TEMPLATE_TYPE_ID);

        // Get all the templateMarketList where templateTypeId is less than or equal to SMALLER_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldNotBeFound("templateTypeId.lessThanOrEqual=" + SMALLER_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsLessThanSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId is less than DEFAULT_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldNotBeFound("templateTypeId.lessThan=" + DEFAULT_TEMPLATE_TYPE_ID);

        // Get all the templateMarketList where templateTypeId is less than UPDATED_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldBeFound("templateTypeId.lessThan=" + UPDATED_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateTypeIdIsGreaterThanSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        // Get all the templateMarketList where templateTypeId is greater than DEFAULT_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldNotBeFound("templateTypeId.greaterThan=" + DEFAULT_TEMPLATE_TYPE_ID);

        // Get all the templateMarketList where templateTypeId is greater than SMALLER_TEMPLATE_TYPE_ID
        defaultTemplateMarketShouldBeFound("templateTypeId.greaterThan=" + SMALLER_TEMPLATE_TYPE_ID);
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByEvaluationDataIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);
        EvaluationData evaluationData = EvaluationDataResourceIT.createEntity(em);
        em.persist(evaluationData);
        em.flush();
        templateMarket.setEvaluationData(evaluationData);
        templateMarketRepository.saveAndFlush(templateMarket);
        Long evaluationDataId = evaluationData.getId();

        // Get all the templateMarketList where evaluationData equals to evaluationDataId
        defaultTemplateMarketShouldBeFound("evaluationDataId.equals=" + evaluationDataId);

        // Get all the templateMarketList where evaluationData equals to evaluationDataId + 1
        defaultTemplateMarketShouldNotBeFound("evaluationDataId.equals=" + (evaluationDataId + 1));
    }


    @Test
    @Transactional
    public void getAllTemplateMarketsByTemplateScoreRecordIsEqualToSomething() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);
        TemplateScoreRecord templateScoreRecord = TemplateScoreRecordResourceIT.createEntity(em);
        em.persist(templateScoreRecord);
        em.flush();
        templateMarket.addTemplateScoreRecord(templateScoreRecord);
        templateMarketRepository.saveAndFlush(templateMarket);
        Long templateScoreRecordId = templateScoreRecord.getId();

        // Get all the templateMarketList where templateScoreRecord equals to templateScoreRecordId
        defaultTemplateMarketShouldBeFound("templateScoreRecordId.equals=" + templateScoreRecordId);

        // Get all the templateMarketList where templateScoreRecord equals to templateScoreRecordId + 1
        defaultTemplateMarketShouldNotBeFound("templateScoreRecordId.equals=" + (templateScoreRecordId + 1));
    }

    /**
     * Executes the search, and checks that the default entity is returned.
     */
    private void defaultTemplateMarketShouldBeFound(String filter) throws Exception {
        restTemplateMarketMockMvc.perform(get("/api/template-markets?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(templateMarket.getId().intValue())))
            .andExpect(jsonPath("$.[*].templateId").value(hasItem(DEFAULT_TEMPLATE_ID.intValue())))
            .andExpect(jsonPath("$.[*].appClassId").value(hasItem(DEFAULT_APP_CLASS_ID.intValue())))
            .andExpect(jsonPath("$.[*].pageSchemaIds").value(hasItem(DEFAULT_PAGE_SCHEMA_IDS.toString())))
            .andExpect(jsonPath("$.[*].assetsType").value(hasItem(DEFAULT_ASSETS_TYPE)))
            .andExpect(jsonPath("$.[*].createUser").value(hasItem(DEFAULT_CREATE_USER)))
            .andExpect(jsonPath("$.[*].createTime").value(hasItem(DEFAULT_CREATE_TIME.toString())))
            .andExpect(jsonPath("$.[*].appClassName").value(hasItem(DEFAULT_APP_CLASS_NAME)))
            .andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString())))
            .andExpect(jsonPath("$.[*].templateTypeId").value(hasItem(DEFAULT_TEMPLATE_TYPE_ID.intValue())));

        // Check, that the count call also returns 1
        restTemplateMarketMockMvc.perform(get("/api/template-markets/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("1"));
    }

    /**
     * Executes the search, and checks that the default entity is not returned.
     */
    private void defaultTemplateMarketShouldNotBeFound(String filter) throws Exception {
        restTemplateMarketMockMvc.perform(get("/api/template-markets?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$").isArray())
            .andExpect(jsonPath("$").isEmpty());

        // Check, that the count call also returns 0
        restTemplateMarketMockMvc.perform(get("/api/template-markets/count?sort=id,desc&" + filter))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(content().string("0"));
    }

    @Test
    @Transactional
    public void getNonExistingTemplateMarket() throws Exception {
        // Get the templateMarket
        restTemplateMarketMockMvc.perform(get("/api/template-markets/{id}", Long.MAX_VALUE))
            .andExpect(status().isNotFound());
    }

    @Test
    @Transactional
    public void updateTemplateMarket() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        int databaseSizeBeforeUpdate = templateMarketRepository.findAll().size();

        // Update the templateMarket
        TemplateMarket updatedTemplateMarket = templateMarketRepository.findById(templateMarket.getId()).get();
        // Disconnect from session so that the updates on updatedTemplateMarket are not directly saved in db
        em.detach(updatedTemplateMarket);
        updatedTemplateMarket
            .templateId(UPDATED_TEMPLATE_ID)
            .appClassId(UPDATED_APP_CLASS_ID)
            .pageSchemaIds(UPDATED_PAGE_SCHEMA_IDS)
            .assetsType(UPDATED_ASSETS_TYPE)
            .createUser(UPDATED_CREATE_USER)
            .createTime(UPDATED_CREATE_TIME)
            .appClassName(UPDATED_APP_CLASS_NAME)
            .description(UPDATED_DESCRIPTION)
            .templateTypeId(UPDATED_TEMPLATE_TYPE_ID);
        TemplateMarketDTO templateMarketDTO = templateMarketMapper.toDto(updatedTemplateMarket);

        restTemplateMarketMockMvc.perform(put("/api/template-markets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateMarketDTO)))
            .andExpect(status().isOk());

        // Validate the TemplateMarket in the database
        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeUpdate);
        TemplateMarket testTemplateMarket = templateMarketList.get(templateMarketList.size() - 1);
        assertThat(testTemplateMarket.getTemplateId()).isEqualTo(UPDATED_TEMPLATE_ID);
        assertThat(testTemplateMarket.getAppClassId()).isEqualTo(UPDATED_APP_CLASS_ID);
        assertThat(testTemplateMarket.getPageSchemaIds()).isEqualTo(UPDATED_PAGE_SCHEMA_IDS);
        assertThat(testTemplateMarket.getAssetsType()).isEqualTo(UPDATED_ASSETS_TYPE);
        assertThat(testTemplateMarket.getCreateUser()).isEqualTo(UPDATED_CREATE_USER);
        assertThat(testTemplateMarket.getCreateTime()).isEqualTo(UPDATED_CREATE_TIME);
        assertThat(testTemplateMarket.getAppClassName()).isEqualTo(UPDATED_APP_CLASS_NAME);
        assertThat(testTemplateMarket.getDescription()).isEqualTo(UPDATED_DESCRIPTION);
        assertThat(testTemplateMarket.getTemplateTypeId()).isEqualTo(UPDATED_TEMPLATE_TYPE_ID);
    }

    @Test
    @Transactional
    public void updateNonExistingTemplateMarket() throws Exception {
        int databaseSizeBeforeUpdate = templateMarketRepository.findAll().size();

        // Create the TemplateMarket
        TemplateMarketDTO templateMarketDTO = templateMarketMapper.toDto(templateMarket);

        // If the entity doesn't have an ID, it will throw BadRequestAlertException
        restTemplateMarketMockMvc.perform(put("/api/template-markets").with(csrf())
            .contentType(MediaType.APPLICATION_JSON)
            .content(TestUtil.convertObjectToJsonBytes(templateMarketDTO)))
            .andExpect(status().isBadRequest());

        // Validate the TemplateMarket in the database
        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeUpdate);
    }

    @Test
    @Transactional
    public void deleteTemplateMarket() throws Exception {
        // Initialize the database
        templateMarketRepository.saveAndFlush(templateMarket);

        int databaseSizeBeforeDelete = templateMarketRepository.findAll().size();

        // Delete the templateMarket
        restTemplateMarketMockMvc.perform(delete("/api/template-markets/{id}", templateMarket.getId()).with(csrf())
            .accept(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());

        // Validate the database contains one less item
        List<TemplateMarket> templateMarketList = templateMarketRepository.findAll();
        assertThat(templateMarketList).hasSize(databaseSizeBeforeDelete - 1);
    }
}
